IconBox = {}

icon = {}

function IconBox.new (x, y, long, haut)
  ibx = x
  iby = y
  ibx2 = x + long
  iby2 = y + haut
  return ibx, iby, ibx2, iby2
end

function IconBox.addIcon (x, y, nb, bx, name, text, colortxt, color)
  icon.nb = nb
  _G[icon.nb] = {}
  _G[icon.nb].name = name
  _G[icon.nb].text = text
  _G[icon.nb].color = color
  _G[icon.nb].colortxt = colortxt
  
  local cfdtxt = _G[icon.nb].colortxt
  
  _G[icon.nb].colorfdtxt = Color.invert (cfdtxt)
  _G[icon.nb].x = x
  _G[icon.nb].y = y
  _G[icon.nb].box = newBox (x, y, x+32, y+46)
  
  local xx = ibx + _G[icon.nb].x
  local yy = iby + _G[icon.nb].y
  
  screen.drawFillRect (SCREEN_DOWN, xx, yy, xx+32, yy+32, color)
  
  local x1 = (xx+32/2)-((string.len (_G[icon.nb].text)*6)/2)
  local y1 = yy+35
  
  screen.print (SCREEN_DOWN, x1, y1, _G[icon.nb].text, _G[icon.nb].colortxt)
  
  local x2 = string.len (_G[icon.nb].text)*6
  local y2 = y1+11
  
  screen.drawFillRect (SCREEN_DOWN, x1, y1, x2, y2, _G[icon.nb].colorfdtxt)
  
  if Stylus.newPressinBox (_G[icon.nb].box, ix, iy) then
    _G[icon.nb].color = Color.invert (_G[icon.nb].color)
    
    local ctxt = _G[icon.nb].colortxt
    
    _G[icon.nb].colortxt = Color.invert (ctxt)
  end
end

function IconBox.clear ()
  _G[icon.nb] = nil
  icon.nb = nil
  icon = nil
  ibx = nil
  iby = nil
  ibx2 = nil
  iby2 = nil
end
